package init

import (
	"api/basic/global"
	__ "api/basic/proto"
	"flag"
	"github.com/go-kit/kit/sd/consul"
	"github.com/hashicorp/consul/api"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
)

func init() {
	GrpcInit()
	//Consul()
}

var con *api.Client

func Consul() {

	client := consul.NewClient(con)
	err := client.Register(&api.AgentServiceRegistration{

		ID:      "sd",
		Name:    "sd",
		Tags:    []string{"sd"},
		Port:    2,
		Address: "sss",
	})
	if err != nil {
		return
	}

}

func GrpcInit() {
	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:8901", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	global.S = __.NewOnlineRetailersServerClient(conn)
}
